# 异常发生后，打印异常堆栈信息到文件中

import traceback
import logging

logging.basicConfig(filename="2.log")

try:
    b = 0
    c = a / b
    print(c)
except Exception:
    # 方式二
    s = traceback.format_exc()
    logging.error(s)

